package org.jetnuke.repository;

import net.jforum.cache.CacheEngine;
import net.jforum.cache.Cacheable;

import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.dao.MainConfigDAO;
import org.jetnuke.entities.MainConfig;

public class MainConfigRepository implements Cacheable {
	
	private static CacheEngine cache;
	private static final String FQN="jetnuke/mainConfig";
	public void setCacheEngine(CacheEngine cacheEngine) {
		cache = cacheEngine;
		
	}
	
	public static void loadMainConfig()
	{
		try {
			MainConfigDAO dao=DataAccessDriver.getInst().newMainConfigDAO();
			cache.add(FQN, dao.getMainConfig());
		}
		catch (Exception e) {
			throw new RuntimeException("Error while loading the mainConfig: " + e);
		}
	}
	
	
	 public static MainConfig getMainConfig()throws Exception{
		MainConfig cfg=(MainConfig)cache.get(FQN);
		return cfg;
	}
	public synchronized static void clearCache() {
		cache.remove(FQN);
	}
}
